package com.summer.mall.controller.admin;

import com.summer.mall.common.Const;
import com.summer.mall.common.ResponseCode;
import com.summer.mall.common.ResponseService;
import com.summer.mall.entity.User;
import com.summer.mall.service.StatisticService;
import com.summer.mall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/manage/statistic")
public class StatisticManageController {
    @Autowired
    private UserService userService;

    @Autowired
    private HttpSession session;

    @Autowired
    private StatisticService statisticService;

    /**
     * 获取三大数据接口
     * @param session
     * @return
     */

    @GetMapping(value = "basecount")
    @ResponseBody
    public ResponseService getBaseCount(HttpSession session){
        User currentUser = (User) session.getAttribute(Const.CURRENT_USER);
        if (currentUser == null) {
            return ResponseService.createByCodeErrorMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
        }
        //校验是不是管理员用户
        if (userService.checkAdminRole(currentUser).isSuccess()) {
            System.out.println(statisticService.basecount());
            return statisticService.basecount();
        } else {
            return userService.checkAdminRole(currentUser);
        }
    }
}
